<?php
namespace app\admin\controller;
use think\Db;
use app\admin\model\CommonModel;

/**
 * By：wl
 * Date：2018.11
 * Function:角色权限
 */

class Role extends Base
{
    public function index()
    {   
        //分页查询
        $orderBy = ['id' => 'desc'];
        $lists = Db::table('admingroup')->where('status','<>',3)->where($where)->order($orderBy)->paginate(12,false,['query' => request()->param()]);

        $page = $lists->render();
        $lists = $lists->all(); 
        
        $this->assign('lists', $lists);
        $this->assign('page', $page);
   
        //权限查询
        $list = Db::query('select * from admin_menu where pid=0 and status != 2 order by rank desc ');  
        foreach ($list as $k => $v) {
            $id = $v['id'];
            $list[$k]['data'] = Db::query("select * from admin_menu where pid=$id and status != 2 order by rank desc");
            foreach ($list[$k]['data'] as $kk => $vv) {
      
                if($vv['controller'] == ''){
                    $ids = $vv['id'];
                    $list[$k]['data'][$kk]['data2'] =  Db::query("select * from admin_menu where pid=$ids and status != 2 order by rank desc");
                }else{
                    $list[$k]['data'][$kk]['data2'] = '';
                }
            }

        }
        $this->assign("list",$list);
        // print_r($list);

    	return view();
    }
    public function add_edit()
    {
        $data = $_GET;
        $res = CommonModel::write($data,'admingroup');
        if($res){
            echojson(true,1,'操作成功');
        }else{
            echojson(false,0,'操作失败');
        }
    }
    public function del(){
        $id = $_POST['id'];

        $res = Db::table('admingroup')
                        ->where('id', $id)
                        ->update([
                            'status' => 3,
                        ]);
        if($res){
            echojson(true,1,'操作成功');
        }else{
            echojson(false,0,'操作失败');
        }
    }
   
}

